package com.cskaoyan.controller;

import com.cskaoyan.bean.basebean.BaseParam;
import com.cskaoyan.bean.basebean.BaseRespVo;
import com.cskaoyan.bean.Ad;
import com.cskaoyan.bean.basebean.BasePageData;
import com.cskaoyan.exception.AdException;
import com.cskaoyan.service.AdService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lxy
 * @create 2021-10-18 19:00
 */
@RestController
@RequestMapping("admin/ad")
public class AdController {

    @Autowired
    AdService adService;

    @RequiresPermissions(value = "admin:ad:list")
    @RequestMapping("list")
    public BaseRespVo list(String name, String content, BaseParam baseParam) {
        BasePageData data = adService.query(name, content, baseParam);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions(value = "admin:ad:delete")
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Ad ad) throws AdException {
        adService.deleteAd(ad);
        return BaseRespVo.ok();
    }

    @RequiresPermissions(value = "admin:ad:update")
    @PostMapping("update")
    public BaseRespVo update(@RequestBody Ad ad) throws AdException {
        adService.updateAd(ad);
        return BaseRespVo.ok(ad);
    }

    @RequiresPermissions(value = "admin:ad:create")
    @PostMapping("create")
    public BaseRespVo create(@RequestBody Ad ad) throws AdException {
        adService.createAd(ad);
        return BaseRespVo.ok(ad);
    }

}
